package com.selftcp;

import java.net.InetAddress;

public class ClientTest {
    public static void main(String[] args) {
        // 启动客户端
        try {
            TCPClient client = new TCPClient();
            TCPConnection conn = client.connect(InetAddress.getLocalHost(), 12345);
            System.out.println("Client connected to server");
            
            // 发送测试数据，包含不同长度的消息以触发粘包和拆包
            String[] messages = {
                "Short message 1",
                "This is a longer message that will be split into multiple packets because it exceeds the MSS size",
                "Another short message",
                "Very long message to demonstrate how TCP splits data into multiple segments. This should definitely be split into several packets due to our small MSS setting."
            };
            
            for (String message : messages) {
                byte[] data = message.getBytes();
                System.out.println("Client sent " + data.length + " bytes: " + message);
                conn.send(data);
                
                // 接收服务器返回的数据
                byte[] response = conn.receive();
                System.out.println("Client received " + response.length + " bytes: " + new String(response) + "\n");
                
                Thread.sleep(500);
            }
            
            conn.close();
            client.close();
            System.out.println("Client disconnected");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
